<template>
<div>
	<content_top title="编辑资料">
		<div slot="right" style="display: inline-block;float: right;margin-left:5px;">
			<Button @click="$router.back()"><Icon type="ios-arrow-back" size="16" style="margin-right:5px;" />返回</Button>
		</div>
	</content_top> 
    <div class="menu">
		<ul>
			<li><a @click="$router.push({name:'user_view',params:{id:id}})">用户详情</a></li>
			<li class="cur"><a>编辑资料</a></li>
			<li><a @click="$router.push({name:'user_log',params:{id:id}})">登录日志</a></li>
		</ul>
	</div>
	<div class="g_box">
		<div class="g_head">
			<h3>编辑资料</h3>
		</div>
		<div class="g_box_con" style="padding: 30px 50px;width:900px;;">
			<Form :model="info" label-position="right" :label-width="150" :rules="CheckRule" ref="form">
				<Row>
					<Col span="12">
						<FormItem label="员工编号:" prop="username">
							<Input :value="info.username" disabled style="width:240px;"></Input>
						</FormItem>
						<FormItem label="中文名:" prop="nickname">
							<Input v-model="info.nickname" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="英文名:" prop="en_name">
							<Input v-model="info.en_name" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="性别:" prop="sex">
							<RadioGroup v-model="info.sex">
								<Radio label="0">未知</Radio>
								<Radio label="1">男</Radio>
								<Radio label="2">女</Radio>
							</RadioGroup>
						</FormItem>
						<FormItem label="合同单位:" prop="company">
							<company_list v-model="info.company" style="width:240px" field="sx_name"></company_list>
						</FormItem>
						<FormItem label="所属部门:" prop="bumen">
							<bumen_list v-model="info.bumen" style="width:240px" field="name" @change="bumen_change"></bumen_list>
						</FormItem>
					</Col>
					<Col span="12">
						<FormItem label="所在地:" prop="region">
							<region_list v-model="info.region" style="width:240px" field="name"></region_list>
						</FormItem>
						<FormItem label="职级:">
							<Input v-model="info.rank" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="手机号码:">
							<Input v-model="info.mobile" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="Email:">
							<Input v-model="info.email" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="电话分机:">
							<Input v-model="info.phone"  style="width:240px;"></Input>
						</FormItem>
						<FormItem label="设置新密码:" >
							<Input v-model="info.password" type="password" placeholder="为空默认不修改" style="width:240px;"></Input>
						</FormItem>
						<FormItem label="确认密码:">
							<Input v-model="info.confirm_password" type="password" style="width:240px;"></Input>
						</FormItem>
					</Col>
				</Row>
				
			</Form>
			
			<div style="text-align: center;margin: 30px;">
				<Button type="primary" @click="handleSubmit('form')">提交</Button>
			</div>
		</div>
	</div>
	
</div>
</template>

<script>
import company_list from '@/themes/components/company_list';
import bumen_list from '@/themes/components/bumen_list';
import region_list from '@/themes/components/region_list';


export default {
    name: 'admin_info',
	components:{
		company_list,
		region_list,
		bumen_list
	},
    data(){
        return {
            info:{
				username:'',
				nickname:'',
				en_name:'',
				sex:'0',
				company:'',
				bumen:'',
				
				region:'',
				rank:'',
				mobile:'',
				email:'',
				phone:'',
				password:'',
				confirm_password:'',
			},
			CheckRule:{
				username:[
					{ required: true, message: '请填写员工编号', trigger: 'blur' }
				],
				nickname:[
					{ required: true, message: '请填写中文名', trigger: 'blur' }
				],
				en_name:[
					{ required: true, message: '请填写英文名', trigger: 'blur' }
				],
				sex:[
					{ required: true, message: '请选择性别', trigger: 'blur' }
				],
				company:[
					{ required: true, message: '请选择合同单位', trigger: 'blur' }
				],
				bumen:[
					{ required: true, message: '请选择部门', trigger: 'blur' }
				],
				region:[
					{ required: true, message: '请选择地区', trigger: 'blur' }
				],
			},
			id:0
        };
    },
	created(){
		this.id = this.$route.params.id;
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			var postdata = {
				id:this.id
			};
			
			Whttp.load('User/User/get_info',postdata,function(result){
				for(var i in result){
					self.info[i] = result[i];
				}
			});
		},
		handleSubmit(name) {
			this.$refs[name].validate((valid) => {
				if (valid) {
					this.save();
				}
			})
		},
		save(){
			var self = this;
			var postdata = this.info;
			postdata['id'] = this.id;
			
			Whttp.load('User/User/update',postdata,function(result){
				self.$Message.info('修改成功');
				
			});
		},
		bumen_change(val){
			var bumens = [];
			for(var i=0;i<val.length;i++){
				bumens.push(val[i].value);
			}
			
			this.info.bumen = bumens.join(',');
		}
	}
};
</script>
<style scoped>
	@import './info.css';
</style>